Class Concert


  • public class Concert
    extends Event
    Represents a concert of a certain artist with a certain set list as a specific event.

    As an extension of a generic event a concert provides the possibility to store the setlist. The setlist is the sequence of non-null tracks played at a concert. Class concert provides methods to add tracks to the (end of the) tracklist and to reset the tracklist all together (empty it).

    Since:
    ExerciseSheet03
    Version:
    1
    Author:
    Jonas Altrock (ew20b126@technikum-wien.at)
    • Field Detail

      • nextIdx

        private int nextIdx
        next free index
      • setList

        private Track[] setList
        array holding the tracks of the setlist
    • Constructor Detail

      • Concert

        public Concert()
    • Method Detail

      • addTrack

        public boolean addTrack​(Track t)
        adds a track to the set list

        Tracks are added to the end of the list with the first track played at the concert being stored at the beginning of the list. This method returns whether the non-null track was successfully added to the setlist or not. This method does not accept/ignores null tracks.

        Parameters:
        t - the track to add
        Returns:
        true if the track was added, false otherwise
      • ensureCapacity

        private void ensureCapacity​(int length)
        ensures sufficient storage for a specific number of tracks in the setlist

        If the requested capacity can not be ensured before the call, this method increases storage thereby keeping all existing entries.

        Parameters:
        length - the maximum number of tracks this concert must be able to keep in the setlist
      • getSetList

        public Track[] getSetList()
        gets the setlist

        This method returns a defensive copy, meaning it returns a copy of the setlist, which contains (deep) copies of the tracks in the setlist. The returned array does not contain any null entries. If the setlist is empty an array of length 0 is returned.

        Returns:
        the setlist of this concert
      • setSetList

        public void setSetList​(Track[] tracks)
        sets the setList

        This method creates a defensive copy, meaning it sets the setlist of this concert to contain (deep copies of) all non-null tracks of the argument (and only those) thereby preserving the relative ordering of entries. Null entries in the argument are ignored and not part of the resulting setlist. A null argument is generally ignored.

        Parameters:
        tracks - the tracks for the setlist
      • resetSetList

        public void resetSetList()
        removes all tracks from the setlist
      • nrTracks

        public int nrTracks()
        get the length of the playlist the length of the playlist is the number of entries in the setlist.
        Returns:
        the number of tracks in the setlist
      • duration

        public int duration()
        calculates the total duration (in seconds) of all tracks in the setlist

        More specifically the method returns an estimation (lower bound) since tracks with unknown duration are treated having duration 0.

        Returns:
        the total duration of the setlist in seconds
      • impact

        public int impact()
        returns the impact of this event

        the impact is an estimation of the number of people who took notice of this event. For a concert, the impact is calculated from the number of attendees and the length of the concert. The number of attendees is multiplied by the duration factor, which is initially 1 but increases by one for every started half hour the concert lasts. E.G: 400 people attending the concert. 75 minutes duration; duration factor=3 (two full half hours, plus one started half hour) impact therefore is 400*3.

        Overrides:
        impact in class Event
        Returns:
        the impact
      • toString

        public java.lang.String toString()
        returns a String representation of this concert

        the string representation of a concert appends the following line to the string representation of a generic event (without quotes):

         "number of tracks" tracks played, total duration "time".
         

        time is displayed in the format hh:mm with leading zeros

        Overrides:
        toString in class Event
        Returns:
        the string representation